package ComDirectBehaviour;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

import Message.MEnnemie;
import Message.MState;
import Message.ReqReparation;
import jade.core.AID;
import jade.core.behaviours.Behaviour;
import jade.lang.acl.ACLMessage;
import jade.lang.acl.UnreadableException;
import Goal.GoalBase;
import Perception.PerceptsBase;
import Perception.Percepts;
import Message.MNoeud;
import Message.MEnnemie;
import Message.MReparationOK;
import java.util.HashSet;
/**
 * TODO description
 */
public class ComInfoSab extends Behaviour {

	
	
	public void checkMessage(ACLMessage msg)
	{
		original(msg);
		checkInfo(msg);
	}

	public void checkInfo(ACLMessage msg) 
	{
			try{
				String id =msg.getConversationId(); 
				if(id.equals("Target"))
				{
					MEnnemie enn = (MEnnemie)msg.getContentObject();
					
					if(enn.isDisabled())
						return;
					if(!enn.getHelp())
					{
						goals.addGoal(enn.getName()+"-"+enn.getPos());
						HashSet<String> liste = (HashSet<String>)(goals.getAllGoals().clone());
						for(String goal : liste)
						{
							if(goal.contains(enn.getName()+"-"))
								goals.removeGoal(goal);
						}
					}
					else
					{
						HashSet<String> liste = (HashSet<String>)(goals.getAllGoals().clone());
						for(String goal : liste)
						{
							if(goal.contains(enn.getName()+"-"))
								goals.removeGoal(goal);
						}
						goals.addGoal(enn.getName()+"-"+enn.getPos());
					}
				}
			}
			catch(UnreadableException e)
			{
				System.err.println(e.getMessage());
			}
	}
	
}